package com.sg.service.biz.component.nb;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.biz.component.req.ImplementSingleMultipleFieldSetDataEntryReqDto;
import com.sg.dto.biz.component.req.ImplementSingleSetDataEntryReqDto;
import com.sg.dto.biz.component.res.ImplementSingleMultipleFieldSetDataEntryRespDto;
import com.sg.dto.biz.component.res.ImplementSingleSetDataEntryRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
public class NbDataSetSingleEntry {
    /**
     * code:objectToData
     * name:M2执行单条转数据集
     * desc:undefined
     * gen by moon at 5/18/2024, 7:24:01 PM
     **/
    @Trace(operationName = "M2执行单条转数据集")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementSingleSetDataEntryRespDto implementSingleSetDataEntry(ImplementSingleSetDataEntryReqDto reqDto) {
        ImplementSingleSetDataEntryRespDto retData = new ImplementSingleSetDataEntryRespDto();
        List<String> datas = Arrays.asList(reqDto.getDatasetField().split(","));
        List<String> newDatas = new ArrayList<>();
        for (String one : datas) {
            newDatas.add(CommonFunctionHelper.getFilePath(one));
        }
        retData.setSingleSetDataEntryList(newDatas);
        return retData;
    }

    /**
     * code:objectToData
     * name:M2执行单条多字段转数据集（特殊方法）
     * desc:undefined
     * gen by moon at 6/8/2024, 8:05:40 PM
     **/
    @Trace(operationName = "M2执行单条多字段转数据集（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementSingleMultipleFieldSetDataEntryRespDto implementSingleMultipleFieldSetDataEntry(ImplementSingleMultipleFieldSetDataEntryReqDto reqDto) {
        ImplementSingleMultipleFieldSetDataEntryRespDto retData = new ImplementSingleMultipleFieldSetDataEntryRespDto();
        List<ImplementSingleMultipleFieldSetDataEntryReqDto> reqList = new ArrayList<>();
        reqList.add(reqDto);
        retData.setComDatasList(reqList.stream().map(p -> {
            ComDatasDto elm = new ComDatasDto();
            BeanUtil.copyProperties(p, elm);
            return elm;
        }).collect(Collectors.toList()));
        return retData;
    }
    //手工接入方法
}
